#include<iostream>
using namespace std;
int main()
{
    int M,k;
	long number;
    cin>>M;
    for(int i=1;i<=M;i++){
        cin>>k;
        for(int j=1;j<11;j++){
            number=j*k*k;
            if(k==number%10000||k==number%1000||k==number%100||k==number%10||k==number){
            	cout<<j<<" "<<number<<endl;
            	break;
			}
            else if(j==10)
                printf("No\n");
        }
    }
    return 0;
}
